#include<iostream>

#include<stdio.h>

#include<unistd.h>

#include<signal.h>

#include <sys/types.h>

#include <sys/wait.h>

using namespace std;

void my_handler(int sig)
{
    cout << "收到一个信号：" << sig <<endl;
    int rid = 0;
    while((rid = waitpid(-1, nullptr, WNOHANG)) > 0)
    {
        cout << "等待回收成功，子进程PID：" << rid << endl;
    }
}

int main()
{
    for(int i = 0; i < 6; ++i)
    {
        int ret = fork();
        if(ret == 0)
        {
            int cnt = 5;
            while(cnt--)
            {
                cout << "我是子进程，PID：" << getpid() <<  endl;
                sleep(1);
            }
            cout << "子进程退出" << endl;
            sleep(5);
            exit(0);
        }
    }

    signal(SIGCHLD, SIG_IGN);
    while(1)
    {
        cout << "我是父进程，PID：" << getpid() << endl;
        sleep(1);
    }
    return 0;
}
